"""
    jsonschema关键字描述
    1.type 表示待校验元素的类型
    2.properties 定义待校验的JSON对象中，各个key - value对中value的限制条件
    3.required 定义待校验的JSON对象中，必须存在的key
    4.const JSON元素必须等于指定的内容
    5.pattern 使用正则表达式约束字符串类型数据
    type 的类型 object,array,integer,number(float或int),null,boolean,string
"""
import logging

import jsonschema


class AssertUtils:
    @classmethod
    def common_assert(cls, response, status_code, success, code, message, data):
        assert status_code == response.status_code
        schema = {
            "type": "object",
            "properties": {
                "success": {"const": success},
                "code": {"const": code},
                "message": {"pattern": f"^{message}"},
                "data": {"type": f"{data}"}
            },
            "required": ["success", "code", "message", "data"]

        }
        jsonschema.validate(instance=response.json(), schema=schema)

    @classmethod
    def emp_manage_assert(cls, response, status_code, success, code, message):
        assert status_code == response.status_code
        schema = {
            "type": "object",
            "properties": {
                "success": {"const": success},
                "code": {"const": code},
                "message": {"pattern": f"^{message}"}
            },
            "required": ["success", "code", "message"]
        }
        jsonschema.validate(instance=response.json(), schema=schema)
